package love.yuanmengrobot.thousandlanguagegarden.sys.controller;

import love.yuanmengrobot.thousandlanguagegarden.bus.entity.User;
import love.yuanmengrobot.thousandlanguagegarden.bus.service.UserService;
import love.yuanmengrobot.thousandlanguagegarden.sys.utils.DataGridView;
import love.yuanmengrobot.thousandlanguagegarden.sys.utils.ResultObj;
import love.yuanmengrobot.zframe.ioc.annotation.Autowired;
import love.yuanmengrobot.zframe.mvc.annotation.Controller;
import love.yuanmengrobot.zframe.mvc.annotation.RequestMapping;

/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:CHJY创幻
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/7/4 23:42
 */
@Controller
@RequestMapping("/login")
public class LoginController {

    @Autowired
    UserService userService;

    @RequestMapping("/findUser")
    public DataGridView findUser(User user) {
        try {
            User userResult = userService.queryByLoginNameAndPassword(user);
            if (userResult != null)
                System.out.println("登录查询结果：" + userResult.toString());
            else
                System.out.println("空");
            return new DataGridView(userResult);//默认code=200，表示操作成功
        } catch (Exception e) {
            e.printStackTrace();
            return new DataGridView(-1);//输入code=-1，表示操作失败，默认msg="操作失败";
        }

    }

    @RequestMapping("/insertUser")
    public ResultObj insertUser(User user) {
        try {
            userService.insert(user);
            return ResultObj.UPDATE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.UPDATE_ERROR;
        }

    }

}
